package org.zffc;


import io.seata.server.Server;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Objects;

/**
 * @Description:
 * @Note:
 * @Author: zhangfei
 * @Date: 2025/3/5 13:42
 **/
@SpringBootApplication
@Slf4j
public class ZffcSeataServerApplication {
    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext application = SpringApplication.run(ZffcSeataServerApplication.class, args);
        // 启动 Seata Server
        boolean started = Boolean.FALSE;
        try {
            long start = System.currentTimeMillis();
            Server.start(args);
            started = true;
            long cost = System.currentTimeMillis() - start;
            log.info("seata server started in {} millSeconds", cost);
        } catch (Throwable e) {
            started = Boolean.FALSE;
            log.error("seata server start error: {} ", e.getMessage(), e);
            System.exit(-1);
        }
        Environment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");
        path = Objects.isNull(path)?"":path;
        log.info("\n----------------------------------------------------------\n\t" +
                "Application Zffc-Boot-Seata-Server is running! Access URLs:\n\t" +
                "Local: \t\thttp://localhost:" + port + path + "\n" +
                "----------------------------------------------------------");
    }
}
